package com.deliveryservicesystem.model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 * File Name: Customer.java
 * Version:
 * Description:
 * Package: com.deliveryservicesystem.model.newpackage
 * Author: Lance
 * Date: Jun 24, 2012
 * Editor:
 */
@Entity
@Table(name = "CUSTOMER")
@XmlRootElement
@NamedQueries(
{
    @NamedQuery(name = "Customer.findAll", query = "SELECT c FROM Customer c"),
    @NamedQuery(name = "Customer.findByCustomerNo", query = "SELECT c FROM Customer c WHERE c.customerNo = :customerNo"),
    @NamedQuery(name = "Customer.findByFirstName", query = "SELECT c FROM Customer c WHERE c.firstName = :firstName"),
    @NamedQuery(name = "Customer.findByLastName", query = "SELECT c FROM Customer c WHERE c.lastName = :lastName"),
    @NamedQuery(name = "Customer.findByContactNo", query = "SELECT c FROM Customer c WHERE c.contactNo = :contactNo"),
    @NamedQuery(name = "Customer.findByAddress", query = "SELECT c FROM Customer c WHERE c.address = :address")
})
public class Customer implements Serializable
{

    private static final long serialVersionUID = 1L;
    @Id
    @SequenceGenerator(name = "SEQ_CUSTOMER_NO", sequenceName = "SEQ_CUSTOMER_NO")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_CUSTOMER_NO")
    @Basic(optional = false)
    @Column(name = "CUSTOMER_NO")
    private Integer customerNo;
    @Basic(optional = false)
    @Column(name = "FIRST_NAME")
    private String firstName;
    @Basic(optional = false)
    @Column(name = "LAST_NAME")
    private String lastName;
    @Column(name = "CONTACT_NO")
    private String contactNo;
    @Basic(optional = false)
    @Column(name = "ADDRESS")
    private String address;
    @OneToMany(mappedBy = "customerNo")
    private List<Subscription> subscriptionList;

    public Customer()
    {
    }

    public Customer(Integer customerNo)
    {
        this.customerNo = customerNo;
    }

    public Customer(Integer customerNo, String firstName, String lastName, String address)
    {
        this.customerNo = customerNo;
        this.firstName = firstName;
        this.lastName = lastName;
        this.address = address;
    }

    public Integer getCustomerNo()
    {
        return customerNo;
    }

    public void setCustomerNo(Integer customerNo)
    {
        this.customerNo = customerNo;
    }

    public String getFirstName()
    {
        return firstName;
    }

    public void setFirstName(String firstName)
    {
        this.firstName = firstName;
    }

    public String getLastName()
    {
        return lastName;
    }

    public void setLastName(String lastName)
    {
        this.lastName = lastName;
    }

    public String getContactNo()
    {
        return contactNo;
    }

    public void setContactNo(String contactNo)
    {
        this.contactNo = contactNo;
    }

    public String getAddress()
    {
        return address;
    }

    public void setAddress(String address)
    {
        this.address = address;
    }

    @XmlTransient
    public List<Subscription> getSubscriptionList()
    {
        return subscriptionList;
    }

    public void setSubscriptionList(List<Subscription> subscriptionList)
    {
        this.subscriptionList = subscriptionList;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (customerNo != null ? customerNo.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Customer))
        {
            return false;
        }
        Customer other = (Customer) object;
        if ((this.customerNo == null && other.customerNo != null) || (this.customerNo != null && !this.customerNo.equals(other.customerNo)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "Customer Number: " + customerNo
                + "\nFirst Name: " + firstName
                + "\nLast Name: " + lastName
                + "\nContact Number: " + contactNo
                + "\nAddress: " + address;
    }
}
